<?php
/**
 * Created by PhpStorm.
 * User: zhangjian37
 * Date: 2016/9/11
 * Time: 18:55
 */

$RootDir = $_SERVER['DOCUMENT_ROOT'];
include $RootDir . '/utils/mysql/MysqlUtils.php';
include $RootDir . '/utils/CommonConstant.php';
include $RootDir . '/utils/FileUtils.php';

$user_id = $_POST['user_id'];
$phone = $_POST['phone'];
$check = $_POST['check'];

$curtime = time();

$cout = -1;
$conn = conn_mysql();
//判断手机号码是否使用
$query = "select count(1) as cout from user_info where phone_num = '$phone' limit 1";
$result = queryRecord($query,$conn);
//echo mysql_num_rows($result);
while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
    $cout = $row['cout'];
}
if ($cout == 1 )die("err: 手机号码已经被占用");
$cout = -1;
//判断验证码是否正确
$query = "select count(1) as cout from phone_check where phone = '$phone' and check_info = '$check' and $curtime BETWEEN starttime AND endtime";
$result = queryRecord($query,$conn);
while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
    $cout = $row['cout'];
}
if ($cout != 1 )die("err: 验证码不对");

//保存新手机
$query = "update user_info set phone_num = '$phone' where user_id = '$user_id'";
if (!mysql_query($query,$conn)) {
    die('err: ' . mysql_error());
}

echo 'OK';
mysql_close($conn);